package com.crm.controller;

import com.crm.common.result.AjaxResult;
import com.crm.common.result.ResultVO;
import com.crm.service.IndexService;
import com.crm.vo.BasisStatisticsVO;
import com.crm.vo.SalesStatisticVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

/**
 * \* User: chy
 * \* Date: 2025/9/5  15:29
 * \* Description:首页展示页面
 * \
 */
@RestController
@RequestMapping("/index")
@Slf4j
public class IndexController {
    @Resource
    private IndexService indexService;

    /**
     * 查询首页统计信息
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping
    public ResultVO<BasisStatisticsVO> getBaseInfo(@RequestParam LocalDate beginCreateTime ,
                                @RequestParam LocalDate endCreateTime) {


        log.info("查询首页统计信息。(beginCreateTime={})", beginCreateTime);

        BasisStatisticsVO baseInfo = indexService.getBaseInfo(beginCreateTime, endCreateTime);
        return ResultVO.success(baseInfo);
    }

    /**
     * 获取销售统计信息
     *
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/salesStatistic")
    public AjaxResult getSalesStatistic(@RequestParam LocalDate beginCreateTime ,
                                        @RequestParam LocalDate endCreateTime) {


        log.info("查询首页统计信息。beginCreateTime={}", beginCreateTime);

        List<SalesStatisticVO> salesStatistic = indexService.getSalesStatistic(beginCreateTime, endCreateTime);
        return AjaxResult.success(salesStatistic);
    }

}
